import type { CommonResult } from '../types/global'
import type {
	LoginParams,
	LoginResult,
	UserInfoResult,
	RegisterParams,
} from '../types/login'
import { UserStatsItem } from '../types/user'
import { http } from '@/utils/http'


/**
 * 用户名和密码登录，获取token
 * @param data
 */
export const loginAPI = (data : LoginParams) => {
	return http<LoginResult>({
		url: '/auth/oauth2/token',
		method: 'POST',
		data,
	})
}

/**
 * 退出登录
 */
export const logoutAPI = () => {
	return http<CommonResult>({
		url: '/auth/token/logout',
		method: 'DELETE',
	})
}


/**
 * 获取用户信息
 */
export const getUserInfoAPI = () => {
	return http<UserInfoResult>({
		url: '/admin/tocCustom/info',
		method: 'GET',

	})
}


/**
 * 注册
 * @param params
 */
export const registerAPI = (params : RegisterParams) => {
	return http<CommonResult>({
		url: '/admin/register/custom',
		method: 'POST',
		data: params,
	})
}


/**
 * 获取用户统计数据
 * @returns 
 */
export const getUserStatsAPI = () => {
	return http<UserStatsItem>({
		url: '/fanqie/userStats/getUserStats',
		method: 'GET',
	})
}